package com.yonyou.pmclouds.project.processor;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.team.rmiimpl.TeamMaintainForProject;
import org.apache.commons.lang3.StringUtils;

/**
 * @Description: 更新项目责任人规则（目前只用于与NC对接的情况）
 * @Author: zhangwce
 * @Date: 2018/5/14 11:09
 */
public class OutterUpdateManagerToTeamProcessor implements SingleProcessor<ProjectVO> {
    private TeamMaintainForProject teamMemberMaintain;
    private String enterprise;

    public OutterUpdateManagerToTeamProcessor(TeamMaintainForProject teamMemberMaintain, String enterprise) {
        this.teamMemberMaintain = teamMemberMaintain;
        this.enterprise = enterprise;
    }

    @Override
    public void process(ProjectVO vo, ProjectVO orig) throws BusinessException {

        if (!StringUtils.isEmpty(vo.getManager()) && !StringUtils.equals(vo.getManager(), orig.getManager())) {
            if (StringUtils.isEmpty(orig.getManager())) {
                teamMemberMaintain.insertProjectManager(vo.getManager(), enterprise, orig.getPkProject(), vo.getProjectState());
            } else {
                teamMemberMaintain.updateProjectManager(vo.getManager(), enterprise, orig.getPkProject());
            }
        }
    }

}
